package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.enumeration.OperationType;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface SetmealMapper {
    /**
     * 查询关联分类的套餐数量
     * @param id
     * @return
     */
    int queryByCategoryId(Long id);

    /**
     * 套餐分页查询，并连接查询分类名称
     * @param setmealPageQueryDTO
     * @return
     */
    List<SetmealVO> queryByPageWithCategory(SetmealPageQueryDTO setmealPageQueryDTO);

    @AutoFill(OperationType.INSERT)
    void insert(Setmeal setmeal);

    @Select("select s.*,c.name as categoryName from setmeal s inner join category c on s.category_id = c.id where s.id = #{id};")
    SetmealVO queryBySetmealWithCategory(Long id);

    @AutoFill(OperationType.UPDATE)
    void update(Setmeal setmeal);

    void deleteByIds(List<Integer> ids);

    @Select("select * from setmeal where category_id = #{categoryId};")
    List<Setmeal> queryByCategoryIdList(Integer categoryId);

    @Select("select * from setmeal where id = #{setmealId};")
    Setmeal queryById(Long setmealId);

    /**
     * 根据条件统计套餐数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
